﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Threading;
using System.Web;
using System.Web.Mvc;

namespace CheckWindowsService.Controllers
{
    public class DefaultController : Controller
    {
        //
        // GET: /Default/

        public ActionResult Index(string serviceName)
        {
            ServiceController[] services;
            services = ServiceController.GetServices();

            var found = false;
            if (services.Any(service => service.ServiceName == serviceName))
            {
                var sc = new ServiceController(serviceName);
                Console.WriteLine("Status = " + sc.Status);
                ViewBag.Status = "Service " + serviceName + " status: " + sc.Status;
                found = true;
            }

            if(!found)
                ViewBag.Status = "Service " + serviceName + " not found, no status available.";
            
            return View();
        }

    }
}
